package com.qubi.exchange.util;

import cn.hutool.core.codec.Base64;
import com.alibaba.fastjson.JSONObject;
import com.google.protobuf.InvalidProtocolBufferException;
import com.qubi.exchange.protobuffer.KlinesBuffer;
import com.qubi.exchange.protobuffer.MarketBuffer;
import com.qubi.exchange.script.util.RandomUtil;

import java.io.IOException;
import java.util.ArrayList;


public class ProtostuffUtil {

    public static void main(String[] args) throws InvalidProtocolBufferException {
        byte []s=Base64.decode("H4sIAAAAAAAAAFVWXW9cKQz9LzyPELbBNvO8lfZ9s09VtZrsTNVITRMlaaUqyn9fg+HCPs1wwF+HY1/ew+vvx/un7+EcPt39+fdff9yFU3h7en7415Dr7fntm62fLy+Xx9dwfg/3Dz8uL79t6+3l5y18nML18nYJ58/v4RbOQnIKr//3FM5QaiYBwJLU9n/ZPpJI1cL/gNqZe7P/bFiNirYsMQtC+HIaGBiWIycuCzMIKFYofGBSG5jWWrsvqHlB4lBKy7009xiJSBfWPMWaqB4QN281Vk2yMOmmCHk7x81Wo2bewDLyzZtxbliOwEwLpAY2A13FciOFI4OsDHuUY1VqT0RUFx2lJSwRSlnuS0s4xbJZ9sww5qSLpoKeLsh+slMndXOXnfEoSVatxKNW3AjFfodGFeI8qbG2YtlSzLpAce7LAXhtlO0PzhQpKvVKuM4Y6IQaZCIbGMRcHMOEA0sRHaN8VJxaBP+PNSYefmRUihqh5V8sZZ2YRHUyhWCQjuyKMFuS4RtNzOqkI0zbHLF2DBVHoWhse1oyKMfkN8OQh3+oXQcVaBj15oFoBYyKgXfyoGwNAb3IuZUs9gg3SU37AaipbxuXfjUwqnWagHTwmsfaOR2iBRx6R24d9OUULt7h2Ty2uDmZ7kFHpQ1tBtQcVlwgezOkyrLAloepQicJDVPXIapsB4c4iac4DQTvudq4PDDwmaNbaMAepVbOCyOPjLoiQ29iiZRmEzewV89NsJtH9tBUaJUNXexgIy7rAqdeNmO/eeG80kaPjJxW5N5mJiU85mIDqQ8CVFgxMHtg6/BVTL81sulQNo/cx55F2RzKCE28eRwjmXCV11UOlW24lnXSabRuWFEIhnzKuj/CwU2BFZq87ctWHrVStmXx+YtlUdVHEtr05UUpSf+qpHToiGL2CUIwx17OPpGTbfGMUfwrZVnkOm3Fdd1CzamS1a/DbDXPuDYzx+UeevHJSm1ujVMleVurHEBM0FmTA/AhlTGNFIqr2FTDE/AvouWUjkNGghuqTZyFDcVpHXWXPFUoeSZafNhQncOGk8tcBUae/pkbI4TSUE9LvgnFxsBTOKcP+/0azl8v319v9li4/bjePTze9lcCSrGNb5eX2/U493CdrxF7Y8T5vPj4DwCXQ2m9CAAA");
        try {
              byte[] t=GZipUtils.unGzip(s);
              String ss=new String(t);
            System.out.println(ss);
        } catch (IOException e) {
            e.printStackTrace();
        }


//        KlinesBuffer.Kline.Builder klineBuilder= KlinesBuffer.Kline.newBuilder();
//        KlinesBuffer.KlineList.Builder klinesListBuilder= KlinesBuffer.KlineList.newBuilder();
//        var kl=new ArrayList<double[]>();
//
//
//        for (int i = 0; i <1; i++) {
//            double []  nm={1d+ RandomUtil.getRandomInt(1,1000),2d+ RandomUtil.getRandomInt(1,10001),3d+ RandomUtil.getRandomInt(1,10000),4d+ RandomUtil.getRandomInt(1,10000),5d+ RandomUtil.getRandomInt(1,10000),System.currentTimeMillis()+ RandomUtil.getRandomInt(1,1000)};
//            kl.add(nm);
//            var kline= klineBuilder.setOpen(1f+ RandomUtil.getRandomInt(1,1000)).setHigh(2f+RandomUtil.getRandomInt(1,10000)).setLow(0.5f+RandomUtil.getRandomInt(1,10000)).setClose(1.1f+RandomUtil.getRandomInt(1,10000)).setTime(System.currentTimeMillis()+RandomUtil.getRandomInt(1,10000)).build();
//            klinesListBuilder.addKline(kline);
//
//        }
//
//        var jsonStr= JSONObject.toJSONString(kl);
//         var jsondata= jsonStr.getBytes();
//        var klines= klinesListBuilder.build();
//        var data= klines.toByteArray();
//        System.out.println(data.length/4/1024);
//
//        try {
//          var newData=  GZipUtils.gzip(data);
//            System.out.println(newData.length/4/1024);
//            var newjsondata=GZipUtils.gzip(jsondata);
//            boolean b1=GZipUtils.isGZipped(newjsondata);
//            boolean b2=GZipUtils.isGZipped(jsondata);
//            System.out.println(newjsondata.length/4/1024);
//
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//
//
//        MarketBuffer.marketInfoList.Builder builder=MarketBuffer.marketInfoList.newBuilder();
//        builder.addMarketInfo(   MarketBuffer.MarketInfo.newBuilder().setGain24(1).build());
//        builder.addSymbol(MarketBuffer.Symbol.newBuilder().setAllowBuy(1));
//
////        builder.setTopic("123");
//        byte[]bytes=builder.build().toByteArray();
//        var cc= MarketBuffer.marketInfoList.parseFrom(bytes);
//        System.out.println(bytes);

    }


}
